package com.heima.comment.controller;

import com.heima.comment.dtos.CommentRepayDto;
import com.heima.comment.dtos.CommentRepayLikeDto;
import com.heima.comment.dtos.CommentRepaySaveDto;
import com.heima.comment.service.ApCommentRepayService;
import com.heima.comment.vos.CommentVo;
import com.heima.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/v1/comment_repay")
public class ApCommentRepayController {

    @Autowired
    private ApCommentRepayService apCommentRepayService;

    /**
     * 评论回复
     *
     * @param commentRepaySaveDto 前端dto
     * @return 返回结果
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CommentRepaySaveDto commentRepaySaveDto) {
        apCommentRepayService.save(commentRepaySaveDto);
        return ResponseResult.okResult(null);
    }

    /**
     * 评论回复列表
     *
     * @param commentRepayDto 前端dto
     * @return 返回结果
     */
    @PostMapping("/load")
    public ResponseResult<List<CommentVo>> load(@RequestBody CommentRepayDto commentRepayDto) {
        List<CommentVo> commentVoList = apCommentRepayService.load(commentRepayDto);
        return ResponseResult.okResult(commentVoList);
    }

    /**
     * 评论回复点赞
     *
     * @param commentRepayLikeDto 前端dto
     * @return 返回结果
     */
    @PostMapping("/like")
    public ResponseResult<Map<String, Integer>> like(@RequestBody CommentRepayLikeDto commentRepayLikeDto) {
        Map<String, Integer> data = apCommentRepayService.like(commentRepayLikeDto);
        return ResponseResult.okResult(data);
    }
}
